pandas 1.4.2

ParametersReturns
any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)

Returns False unless there is at least one element within a series or along a Dataframe axis that is True or equivalent (e.g. non-zero or non-empty).

Parameters

axis : {0 or 'index', 1 or 'columns', None}, default 0

Indicate which axis or axes should be reduced.

bool_only : bool, default None

Include only boolean columns. If None, will attempt to use everything, then use only boolean data. Not implemented for Series.

skipna : bool, default True

Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be False, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

level : int or level name, default None

If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar.

**kwargs : any, default None

Additional keywords have no effect but might be accepted for compatibility with NumPy.

Returns

scalar or Series

If level is specified, then, Series is returned; otherwise, scalar is returned.

Return whether any element is True, potentially over an axis.

See Also

DataFrame.all

Return whether all elements are True over requested axis.

DataFrame.any

Return whether any element is True over requested axis.

Series.all

Return whether all elements are True.

Series.any

Return whether any element is True.

numpy.any

Numpy version of this method.

Examples

Series

For Series input, the output is a scalar indicating whether any element is True.

This example is valid syntax, but we were not able to check execution
>>> pd.Series([False, False]).any()
False
This example is valid syntax, but we were not able to check execution
>>> pd.Series([True, False]).any()
True
This example is valid syntax, but we were not able to check execution
>>> pd.Series([], dtype="float64").any()
False
This example is valid syntax, but we were not able to check execution
>>> pd.Series([np.nan]).any()
False
This example is valid syntax, but we were not able to check execution
>>> pd.Series([np.nan]).any(skipna=False)
True

DataFrame

Whether each column contains at least one True element (the default).

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]})
... df A B C 0 1 0 0 1 2 2 0
This example is valid syntax, but we were not able to check execution
>>> df.any()
A     True
B     True
C    False
dtype: bool

Aggregating over the columns.

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({"A": [True, False], "B": [1, 2]})
... df A B 0 True 1 1 False 2
This example is valid syntax, but we were not able to check execution
>>> df.any(axis='columns')
0    True
1    True
dtype: bool
This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({"A": [True, False], "B": [1, 0]})
... df A B 0 True 1 1 False 0
This example is valid syntax, but we were not able to check execution
>>> df.any(axis='columns')
0    True
1    False
dtype: bool

Aggregating over the entire DataFrame with axis=None .

This example is valid syntax, but we were not able to check execution
>>> df.any(axis=None)
True

any for an empty DataFrame is an empty Series.

This example is valid syntax, but we were not able to check execution
>>> pd.DataFrame([]).any()
Series([], dtype: bool)
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#10873
type: <class 'function'>
Commit: